﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Web.Mvc;

namespace olierFrm.Extensions.Html
{
    public static class PagingExtensions
    {
        public static MvcHtmlString Paging(this System.Web.Mvc.HtmlHelper html, string Param, int RowCount, int PageRow = 10)
        {
            return MvcHtmlString.Create(new olierFrm.Web.Paging(Param, RowCount, PageRow).ToString());
        }

        public static MvcHtmlString Paging(this System.Web.Mvc.HtmlHelper html, string Param, DataTable RowCount, int PageRow = 10)
        {
            if (RowCount == null)
            {
                return null;
            }

            int rowcount = int.Parse(RowCount.Rows[0][0].ToString());
            if (rowcount == 0 || rowcount <= PageRow) return null;
            return MvcHtmlString.Create(new olierFrm.Web.Paging(Param, rowcount, PageRow).ToString());
        }

        public static MvcHtmlString Paging(this System.Web.Mvc.HtmlHelper html, DataTable RowCount, int PageRow = 10)
        {
            if (RowCount == null)
            {
                return null;
            }

            int rowcount = int.Parse(RowCount.Rows[0][0].ToString());
            if (rowcount == 0) return null;
            return MvcHtmlString.Create(new olierFrm.Web.Paging(RowCount.TableName + "Page", rowcount, PageRow).ToString());
        }
    }
}
